package com.axter.libs.photo.previewphoto;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.TypedValue;

import uk.co.senab.photoview.PhotoView;

/**
 * @author axter
 */
public class PhotoViewProgress extends PhotoView {
    private Paint paint_progress;

    public PhotoViewProgress(Context context) {
        this(context, null);
    }

    public PhotoViewProgress(Context context, AttributeSet attr) {
        this(context, attr, 0);
    }

    public PhotoViewProgress(Context context, AttributeSet attr, int defStyle) {
        super(context, attr, defStyle);
        initProgress();
    }

    private void initProgress() {
        DisplayMetrics dm = getResources().getDisplayMetrics();
        int width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, dm);
        int textsize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 30, dm);

        paint_progress = new Paint();
        paint_progress.setColor(Color.WHITE);
        paint_progress.setStrokeWidth(width);
        paint_progress.setTextSize(textsize);
        paint_progress.setTextAlign(Paint.Align.CENTER);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        if (isShowProgress) {
            canvas.drawText(progressTitle, getWidth() >> 1, getHeight() >> 1, paint_progress);
        } else {
            super.onDraw(canvas);
        }
    }

    private boolean isShowProgress = false;
    private String progressTitle = "";

    public void showTip(String msg) {
        isShowProgress = true;
        progressTitle = msg;
        postInvalidate();
    }

    public void hideTip() {
        isShowProgress = false;
        postInvalidate();
    }
}
